<template>
  <u-popup
    v-model="showModal"
    mode="center"
    :closeable="true"
    negative-top="10"
    border-radius="20"
    :mask-close-able="false"
    close="close"
  >
    <view class="fs-28 col-9 pay-modal-view">
      <view class="col-3 title"
        >尊敬的用户：<br />您好，请确认以下提现信息</view
      >
      <view class="list"
        >到账账号
        <text class="col-3">{{
          (data.arrivalAccount || "") | arrAcc
        }}</text></view
      >
      <view class="list"
        >提现金额
        <text class="col-3">{{ cashTypeEl }}{{ data.num }}</text></view
      >
      <view class="list">
        代缴税收
        <text class="col-3">{{ cashTypeEl }}{{ taxation || 0 }}</text>
      </view>
      <view class="list"
        >税后所得 <text class="col-3">{{ cashTypeEl }}{{ fallNum }}</text></view
      >
      <view class="fs-24 note">
        请确认后，输入结算密码：若未设置结算密码，请前往网页版，于“我的账户”-“安全设置”-“结算密码”进行设置。
      </view>
      <!-- <validcode
        :maxlength="6"
        :isPwd="true"
        ref="clearVal"
        @finish="getPwd"
      ></validcode> -->
      <input
        class="pswInput"
        type="password"
        v-model="pswValue"
        :clearable="false"
        cursor-spacing="30"
        @confirm="confirmPay"
      />
      <u-toast ref="uToast" />
    </view>
  </u-popup>
</template>

<script>
import { applyCashWithdrawal } from "@/api/user";
export default {
  props: ["show", "cashTypeEl"],
  data() {
    return {
      showModal: false,
      fallNum: 0,
      taxation: 0,
      data: {},
      pswValue: "",
    };
  },
  mounted() {
    this.showModal = this.show;
  },
  watch: {
    show(newVal, oldVal) {
      this.showModal = newVal;
      this.data = this.$store.state.payModalData;
      if (this.data.settleType === "社保51") {
        this.fallNum = (this.data.num - this.data.num * 0.01).toFixed(2);
        this.taxation = (this.data.num * 0.01).toFixed(2);
      }
      if (this.data.settleType === "云账户") {
        this.fallNum = (this.data.num - this.data.num * 0.005).toFixed(2);
        this.taxation = (this.data.num * 0.005).toFixed(2);
      }
    },
    showModal(val) {
      this.$emit("modalPwd", val);
    },
  },
  methods: {
    confirmPay() {
      let value = this.pswValue;
      if (value.length < 6 || value.length > 20) {
        this.$refs.uToast.show({
          title: "结算密码位数为6-20个字符",
          type: "error",
        });
        return false;
      }
      let data = {
        amount: this.data.num,
        currencyCode: this.data.currencyCode, //CNY,USD,EUR,GBP
        currencyName: this.data.currencyName, //人民币，美元，英镑，欧元
        fileUrls: this.data.fileUrls, //上传图片地址？名称？
        payType: this.data.payType, //提现类型：银行卡 paypal
        settlePassword: value,
        settleType: this.data.settleType, //结算类型：云账户等
        // settleType: judge.billingType ? judge.billingType : judge.result,//云账户等

        userCode: this.$store.state.userData["userCode"],
      };
      uni.showLoading({
        title: "提交中...",
      });
      applyCashWithdrawal(data).then((res) => {
        if (res.message === "success") {
          uni.hideLoading();
          this.$refs.uToast.show({
            title: "申请成功",
            type: "success",
          });
          setTimeout(() => {
            uni.redirectTo({
              url: "/pages/user/payCenter/index",
            });
          }, 1500);
        } else {
          uni.hideLoading();
          this.$refs.uToast.show({
            title: res.message,
            type: "error",
          });
          setTimeout(() => {
            // if (res.message === "结算密码不匹配") {
            //   this.pswValue = "";
            // }
          }, 1500);
        }
      });
    },
    close() {
      this.showModal = false;
    },
  },
};
</script>

<style lang="scss">
.pay-modal-view {
  padding: 20rpx 40rpx 40rpx 40rpx;
  .title {
    margin-top: 28rpx;
    margin-bottom: 20rpx;
  }
  .list {
    line-height: 64rpx;
    text {
      margin-left: 20rpx;
    }
  }
  .note {
    margin: 20rpx 0;
  }
  .pswInput {
    border: 1px solid #ccc;
    height: 80rpx;
    // width: 480rpx;
    // box-sizing: border-box;
    font-size: 28rpx;
    color: #333;
    padding: 0 20rpx;
  }
}
</style>
